package form;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.UserDAO;

import model.User;

/**
 * Servlet implementation class capnhatcapdo
 */
@WebServlet("/capnhatcapdo")
public class capnhatcapdo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public capnhatcapdo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			toDo(request,response);
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			toDo(request,response);
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private void toDo(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, IOException {
		String thamsocapdo =request.getParameter("thamsocapdo");
		int capdo = Integer.parseInt(thamsocapdo);
		String email= request.getParameter("email");
		System.out.println(email);
		String xuly = request.getParameter("xuly");
		System.out.println(capdo);
		if(xuly!=null){
			UserDAO.update(email, capdo);
		}else{
			System.out.println("Không cập nhật được");
		}
		response.sendRedirect("Admin_thanhvien.jsp");
	}

}
